<html>
<head><meta charset="utf-8"><title>Find out if a `CrateId` is from crates.io/sysroot · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html">Find out if a `CrateId` is from crates.io/sysroot</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202557152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202557152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202557152">(Jul 01 2020 at 11:25)</a>:</h4>
<p>When I have a <code>FileId</code>, I can query the owning <code>SourceRoot</code>, which knows whether it's "static" (from <a href="http://crates.io/sysroot">crates.io/sysroot</a>) via <code>is_library</code>. Is there a way to get the same info when I only have a <code>CrateId</code>/<code>CrateData</code> and no <code>SourceDatabaseExt</code> (since I'm in <code>ra_hir_ty</code>)?</p>



<a name="202558062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558062">(Jul 01 2020 at 11:37)</a>:</h4>
<p>The answer is that you shouldn't be asking such questions :-)</p>



<a name="202558108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558108">(Jul 01 2020 at 11:38)</a>:</h4>
<p>Why do you need this info?</p>



<a name="202558123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558123">(Jul 01 2020 at 11:38)</a>:</h4>
<p>More seriously, the <code>Ext</code> setup is specifically so that the compiler doesn't know too much</p>



<a name="202558186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558186">(Jul 01 2020 at 11:39)</a>:</h4>
<p>As an optimization. I want to generate a small-and-expensive-to-recompute index for static crates, and a heavy-but-fast-to-recompute index for workspace crates.</p>



<a name="202558277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558277">(Jul 01 2020 at 11:40)</a>:</h4>
<p>Index here is <code>ImportMap</code>?</p>



<a name="202558315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558315">(Jul 01 2020 at 11:41)</a>:</h4>
<p>No, something like <code>CrateImplDefs</code>, an index of impls</p>



<a name="202558416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558416">(Jul 01 2020 at 11:43)</a>:</h4>
<p>Uhu.... At the moment, our model definitely doesn't allow for that. I am not sure if it should -- seems like this would inevitably add two different code paths, which would need to be unified</p>



<a name="202558418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558418">(Jul 01 2020 at 11:43)</a>:</h4>
<p><code>ImportMap</code> is only consulted for direct dependencies, while for impls we have to look at all transitive deps</p>



<a name="202558520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558520">(Jul 01 2020 at 11:44)</a>:</h4>
<p>Do you think that a call might be helpful?</p>



<a name="202558680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202558680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202558680">(Jul 01 2020 at 11:46)</a>:</h4>
<p>Yeah, that might help</p>



<a name="202561259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202561259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202561259">(Jul 01 2020 at 12:17)</a>:</h4>
<p>Conclusion: <code>impls_from_deps_query</code> is only directly called for leaf crates, so we can maybe speed it up by first computing an <code>FxHashSet&lt;CrateId&gt;</code> transitive closure of dep crates, and then invoking non-transiive version of the query.</p>



<a name="202561358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Find%20out%20if%20a%20%60CrateId%60%20is%20from%20crates.io/sysroot/near/202561358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Find.20out.20if.20a.20.60CrateId.60.20is.20from.20crates.2Eio.2Fsysroot.html#202561358">(Jul 01 2020 at 12:19)</a>:</h4>
<p>A futher optimization would create a query for transitive closure / self. That way, we'll have to do only two hashmap lookups (local crate/some dep), but we won't have to recompure the closure for deps on modifications</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>